package com.ruoyi.energy.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.energy.domain.QyEnterpriseType;
import com.ruoyi.energy.service.IQyEnterpriseTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 企业类型Controller
 *
 * @author cjie
 * @date 2021-11-06
 */
@Api(tags = " 企业类型")
@RestController
@RequestMapping("/qyEnterpriseType")
public class QyEnterpriseTypeController extends BaseController {
    @Autowired
    private IQyEnterpriseTypeService qyEnterpriseTypeService;

    /**
     * 查询企业类型列表
     */
    @ApiOperation(value = "查询企业类型列表", notes = "查询企业类型列表")
    @PreAuthorize(hasPermi = "energy:qyEnterpriseType:list")
    @GetMapping("/list")
    public TableDataInfo list(QyEnterpriseType qyEnterpriseType) {
        startPage();
        List<QyEnterpriseType> list = qyEnterpriseTypeService.selectQyEnterpriseTypeList(qyEnterpriseType);
        return getDataTable(list);
    }

    /**
     * 查询企业类型树形列表
     */
    @ApiOperation(value = "查询类型树列表", notes = "查询类型树列表")
    @PreAuthorize(hasPermi = "energy:qyEnterpriseType:list")
    @GetMapping("/tree")
    public AjaxResult tree(QyEnterpriseType qyEnterpriseType) {
        return qyEnterpriseTypeService.selectTree(qyEnterpriseType);
    }

    /**
     * 导出企业类型列表
     */
    @ApiOperation(value = "导出企业类型列表", notes = "导出企业类型列表")
    @PreAuthorize(hasPermi = "energy:qyEnterpriseType:export")
    @Log(title = "企业类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QyEnterpriseType qyEnterpriseType) throws IOException {
        List<QyEnterpriseType> list = qyEnterpriseTypeService.selectQyEnterpriseTypeList(qyEnterpriseType);
        ExcelUtil<QyEnterpriseType> util = new ExcelUtil<QyEnterpriseType>(QyEnterpriseType.class);
        util.exportExcel(response, list, "企业类型数据");
    }

    /**
     * 获取企业类型详细信息
     */
    @ApiOperation(value = "获取企业类型详细信息", notes = "获取企业类型详细信息")
    @PreAuthorize(hasPermi = "energy:qyEnterpriseType:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(qyEnterpriseTypeService.selectQyEnterpriseTypeById(id));
    }

    /**
     * 新增企业类型
     */
    @ApiOperation(value = "新增企业类型", notes = "新增企业类型")
    @PreAuthorize(hasPermi = "energy:qyEnterpriseType:add")
    @Log(title = "企业类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QyEnterpriseType qyEnterpriseType) {
        return toAjax(qyEnterpriseTypeService.insertQyEnterpriseType(qyEnterpriseType));
    }

    /**
     * 修改企业类型
     */
    @ApiOperation(value = "修改企业类型", notes = "修改企业类型")
    @PreAuthorize(hasPermi = "energy:qyEnterpriseType:edit")
    @Log(title = "企业类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QyEnterpriseType qyEnterpriseType) {
        return toAjax(qyEnterpriseTypeService.updateQyEnterpriseType(qyEnterpriseType));
    }

    /**
     * 删除企业类型
     */
    @ApiOperation(value = "删除企业类型", notes = "删除企业类型")
    @ApiImplicitParam(name = "id", value = "企业类型id", required = true, paramType = "path", dataType = "String")
    @PreAuthorize(hasPermi = "energy:qyEnterpriseType:remove")
    @Log(title = "企业类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") String id) {
        return qyEnterpriseTypeService.deleteQyEnterpriseTypeById(id);
    }
}
